<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-CN">
	
<head>
	<title>变量名 及 命名规范 — Vue.js</title>
	<meta charset="utf-8">
	<meta name="description" content="Vue.js - The Progressive JavaScript Framework">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

	<script src="/js/jquery-3.1.0.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="/js/prettify.js"></script>
	<script type="text/javascript" src="/js/content.js"></script>
	<link rel="stylesheet" href="/css/prettify.css">
	<link rel="icon" href="/images/logo.png" type="image/png">


	<script type="text/javascript" src="/js/vue.js"></script>



	<!-- main page styles -->
	<link rel="stylesheet" href="/css/page.css">
<style type="text/css">
	.content .linenums>ol {
		margin: 0;
		padding-left:35px;
	}
	.hljs-comment,.hljs-quote{color:#8e908c}
	.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#c82829}
	.hljs-built_in,.hljs-builtin-name,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5871f}
	.hljs-attribute{color:#eab700}
	.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#718c00}
	.hljs-section,.hljs-title{color:#4271ae}
	.hljs-keyword,.hljs-selector-tag{color:#8959a8}
	.hljs{display:block;overflow-x:auto;background:#fff;color:#4d4d4c;padding:.5em}
	.hljs-emphasis{font-style:italic}
	.hljs-strong{font-weight:700}
</style>
</head>

<body class="docs">


<div id="header">
	<a id="logo" href="https://cn.vuejs.org/">
		<img src="/images/logo.png">
		<span>Vuecli</span>
	</a>
</div>


<div id="main" class="fix-sidebar">
	<div class="sidebar">
		<div class="sidebar-inner">
			<div class="list">
			<ul class="menu-root">
	<li>
		<h3>ES6 - 简写</h3>
	</li>
	<li id="arrow_function" class="sidebar-menu">
		<i class="">＋</i>
		<a href="/Js/arrow_function" class="sidebar-link">箭头函数</a>
		<ul class="menu-sub">
			<li>
				<a class="section-link" data-scroll="" href="/Js/arrow_function#基本用法">基本用法</a>
			</li>
			<li>
				<a class="section-link" data-scroll="" href="/Js/arrow_function#回调函数特别简洁">回调函数特别简洁</a>
			</li>
			<li>
				<a class="section-link" data-scroll="" href="/Js/arrow_function#箭头函数中的 this">箭头函数中的 this</a>
			</li>
			<li>
				<a class="section-link" data-scroll="" href="/Js/arrow_function#嵌套的 箭头函数">嵌套的 箭头函数</a>
			</li>
		<!-- 			
			<ul>
				<li>
					<a class="section-link" data-scroll="" href="/Js/index#与自定义元素的关系">与自定义元素的关系</a>
				</li>
			</ul> -->
		</ul>
	</li>
	
	<li id="obj_simple" class="sidebar-menu">
		<i class="">＋</i>
		<a href="/Js/obj_simple" class="sidebar-link">对象简写</a>
		<ul class="menu-sub">
			<li>
				<a class="section-link" data-scroll="" href="/Js/obj_simple#属性简写">属性简写</a>
			</li>
			<li>
				<a class="section-link" data-scroll="" href="/Js/obj_simple#方法简洁">方法简洁</a>
			</li>
		</ul>
	</li>
	
	
	<li>
		<h3>Javascript</h3>
	</li>
	
	<li id="variable" class="sidebar-menu">
		<i class="">＋</i>
		<a href="/Js/variable" class="sidebar-link">变量名 及 命名规范</a>
		<ul class="menu-sub">
			<li>
				<a class="section-link" data-scroll="" href="/Js/variable#变量名">变量名</a>
			</li>
			<li>
				<a class="section-link" data-scroll="" href="/Js/variable#命名规范">命名规范</a>
			</li>
		</ul>
	</li>
</ul>
			</div>
		</div>
	</div>

	
<div class="content guide with-sidebar components-guide">
<h1>变量名 及 命名规范</h1>	
<h2 id="变量名">
	<a href="#变量名" class="headerlink" title="变量名" data-scroll="">变量名</a>
</h2>
<ol>
	<li>必须以 <code>字母</code>  <code>"_"</code> 或者 <code>"$"</code> 为开头</li>
	<li>首个字不能为 <code>数字</code>, 中间不允许使用 空格</li>
	<li>严格区分大小写 (javascript就是 区分大小写的)</li>
	<li>不可使用 关键字 和 保留字</li>
	<li>长度不能超过255个字符</li>
</ol>
<p>example</p>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="com">//&nbsp;以字母或下划线_或$开头</span></li><li class="L1"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">ob</span><span class="pun">、</span><span class="pln">AA</span><span class="pun">、</span><span class="pln">$aaa</span><span class="pun">、</span><span class="pln">_fag</span></li><li class="L2"><span class="pun">不合法：</span><span class="pln">oa</span><span class="pun">*</span><span class="pln">b</span><span class="pun">、</span><span class="pln">h</span><span class="pun">&amp;</span><span class="pln">b</span><span class="pun">、</span><span class="pln">hh</span><span class="com">#jj</span></li><li class="L3"><span class="com">//&nbsp;长度不超过255字符</span></li><li class="L4"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">oaaaaaaaaaa</span><span class="pun">、</span><span class="pln">o</span><span class="pun">.........</span><span class="pln">aaaaaaa</span><span class="pun">(......为省略，但是总长不超过</span><span class="lit">255</span><span class="pun">字符)</span></li><li class="L5"><span class="pun">不合法：</span><span class="pln">o</span><span class="pun">.........</span><span class="pln">aaaaaaa</span><span class="pun">(......为省略，但是总长超过</span><span class="lit">255</span><span class="pun">字符)</span></li><li class="L6"><span class="com">//&nbsp;不能使用空格</span></li><li class="L7"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">o_a</span><span class="pun">、</span><span class="pln">o_A</span></li><li class="L8"><span class="pun">不合法：</span><span class="pln">o&nbsp;a</span><span class="pun">、</span><span class="pln">oa&nbsp;a</span><span class="pun">、</span><span class="pln">oA_h&nbsp;h&nbsp;b</span></li><li class="L9"><span class="com">//&nbsp;不能使用关键字及保留字</span></li><li class="L0"><span class="pun">不合法：</span><span class="kwd">class</span><span class="pun">、</span><span class="pln">style</span><span class="pun">、</span><span class="pln">html</span></li><li class="L1"><span class="com">//&nbsp;区分大小写</span></li><li class="L2"><span class="pln">oBtn</span><span class="pun">与</span><span class="pln">obtn</span><span class="pun">不同、</span><span class="pln">oa</span><span class="pun">与</span><span class="pln">oA</span><span class="pun">不同</span></li></ol></code>

<br><br><br>

<h2 id="命名规范">
	<a href="#命名规范" class="headerlink" title="命名规范" data-scroll="">命名规范</a>
</h2>
<h4>1、匈牙利命名法：类型前缀+首字母大写</h4>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;sUserName&nbsp;</span><span class="pun">=</span><span class="pln">&nbsp;</span><span class="str">'css8'</span><span class="pun">;</span></li><li class="L1"><span class="kwd">var</span><span class="pln">&nbsp;iCount&nbsp;</span><span class="pun">=</span><span class="pln">&nbsp;</span><span class="lit">0</span><span class="pun">;</span></li></ol></code>
<table>
	<tr>
		<th>变量类型</th>
		<th>变量前缀</th>
	</tr>
	<tr>
		<td>String 字符串</td>
		<td>s</td>
	</tr>
	<tr>
		<td>Array数组</td>
		<td>a</td>
	</tr>
	<tr>
		<td>Float浮点数</td>
		<td>l</td>
	</tr>
	<tr>
		<td>Funciton函数</td>
		<td>f</td>
	</tr>
	<tr>
		<td>Integer(int)整型</td>
		<td>n</td>
	</tr>
	<tr>
		<td>Object对象</td>
		<td>a</td>
	</tr>
	<tr>
		<td>Regular Expression正则</td>
		<td>r</td>
	</tr>
</table>
<br>


<h4>2、骆驼式/驼峰命名法</h4>
第一个单词首字母 <code>小写</code>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;printLoadTemplates</span><span class="pun">;</span><span class="pln">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="com">//&nbsp;名称首字母小写，其他每个单词的首字母大写</span></li><li class="L1"><span class="kwd">var</span><span class="pln">&nbsp;print_load_templates</span><span class="pun">;</span><span class="pln">&nbsp;&nbsp;&nbsp;</span><span class="com">//&nbsp;下划线法，每个单词用一个下划线标记</span></li></ol></code>
<br>

<h4>3、帕斯卡命名法</h4>
和驼峰命名法类似，但是，而帕斯卡命名法第一个单词首字母也 <code>大写</code>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;</span><span class="typ">PrintLoadTemplates</span><span class="pun">;</span><span class="pln"> </span><span class="com">// 第一个单词首字母也大写</span></li></ol></code>


</div>
		<!-- important -->

<!-- var end -->
</div>	<!-- #main -->

<script>
	
var thisAction = '<?php echo ($thisAction); ?>';

if (thisAction == 'all') {
	// sidebar全部显示
	var $link = $('.content .headerlink');
	var $slink = $('.section-link');
	
}else {
	// 仅展开 当前actionName
	$('.menu-sub').hide();
	$('#'+thisAction+'>a').addClass('current'); 
	$('#'+thisAction+'>i').addClass('sidebar-tap').html('－');
	$('#'+thisAction+' .menu-sub').show();


	$('.sidebar-menu>i').click(function(){
		if($(this).hasClass('sidebar-tap')) {
			$(this).html('＋').toggleClass('sidebar-tap');
			$(this).siblings('.menu-sub').hide();
		}else {
			$('.sidebar-menu>i').html('＋').removeClass('sidebar-tap');
			$('.sidebar-menu .menu-sub').hide();

			$(this).html('－').toggleClass('sidebar-tap');
			$(this).siblings('.menu-sub').show();
		}
	});


	let href = window.location.href;
	let start = href.indexOf('#');
	let href2 = '';
	if(start > 0) {
		href2 = href.slice(start+1);
		$('#'+thisAction+' .section-link[href="#'+href2+'"]').addClass('active');
	}else {
		$('#'+thisAction+' .menu-sub .section-link:first').addClass('active');
	}
 
	var $link = $('.content .headerlink');
	var $slink = $('#'+thisAction+' .menu-sub .section-link');
	
	$('#'+thisAction+' .section-link').click(function(){
		$slink.removeClass('active');
		$(this).addClass('active');
	});
}



// 页面滚动 .sidebar提示 start
let scrollArr = [];
$.each( $link, function() {
	let offset = $(this).offset();
	let thisId = $(this).attr('id');
	scrollArr.push(offset.top);
});


$(window).on('scroll', function(){
	let scrollTop = $(document).scrollTop();
	let nap = 110;
	let slength = scrollArr.length;
	let i=0;
	if(scrollTop < (scrollArr[0]-nap) ) {
	}else if(scrollTop >= scrollArr[slength-1]-nap) {
		i = slength-1;
	}else {
		for(i=0; i<scrollArr.length; i++) {
			if(scrollTop>=scrollArr[i]-nap && scrollTop<scrollArr[i+1]-nap) {
				break;
			}
		}
	}

	if($slink.eq(i).length > 0){
		$slink.removeClass('active');
		$slink.eq(i).addClass('active');
	}
});


</script>

    
  </body>
</html>